package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.LbsTerminalReceiveLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.LbsTerminalReceiveLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-01-17 10:15:48
 */
public class LbsTerminalReceiveLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(LbsTerminalReceiveLogConverts.class);

    public static List<LbsTerminalReceiveLogDTO> convert(List<LbsTerminalReceiveLog> lbsTerminalReceiveLogList) {
        if (CollectionUtils.isEmpty(lbsTerminalReceiveLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<LbsTerminalReceiveLogDTO> lbsTerminalReceiveLogListResult = Lists.newArrayList();
        for (LbsTerminalReceiveLog lbsTerminalReceiveLog : lbsTerminalReceiveLogList) {
            lbsTerminalReceiveLogListResult.add(convert(lbsTerminalReceiveLog));
        }
        return lbsTerminalReceiveLogListResult;
    }

    public static LbsTerminalReceiveLogDTO convert(LbsTerminalReceiveLog lbsTerminalReceiveLog) {
        try {
            return BeanUtils.copy(lbsTerminalReceiveLog, LbsTerminalReceiveLogDTO.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalReceiveLog到LbsTerminalReceiveLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalReceiveLog到LbsTerminalReceiveLogDTO转换失败", e);
        }
    }

    public static LbsTerminalReceiveLog convert(LbsTerminalReceiveLogDTO lbsTerminalReceiveLogDTO) {
        try {
            return BeanUtils.copy(lbsTerminalReceiveLogDTO, LbsTerminalReceiveLog.class);
        } catch (Exception e) {
            LOG.error("LbsTerminalReceiveLogDTO到LbsTerminalReceiveLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "LbsTerminalReceiveLogDTO到LbsTerminalReceiveLog转换失败", e);
        }
    }
}